<template>
  <div class="card-panel" @mouseenter="mouseenter" @mouseleave="mouseleave" >
    <div :style="styleBackground" class="card-panel-icon-wrapper" >
      <svg-icon :icon-class="iconClass" :style="styleColor" class-name="card-panel-icon"/>
    </div>
    <div class="card-panel-description">
      <div class="card-panel-text">
        {{ cardPanelText }}
        <div v-if="labelText" :class="['card-panel-text-label',isDanger?'label-danger':'label-normal']">{{ labelText }}</div>
      </div>
      <div v-if="url" class="card-url">
        <router-link :to="url">
          <count-to :start-val="start" :end-val="total" :duration="duration" class="card-panel-num"/>
        </router-link>
      </div>
      <template v-else>
        <count-to :start-val="start" :end-val="total" :duration="duration" class="card-panel-num"/>
      </template>
      <div v-if="isChart" class="card-panel-chart" @click="handleSetLineChartData(type)">
        <svg-icon icon-class="chart1" class-name="card-panel-chart-icon" />
      </div>
    </div>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  components: {
    CountTo
  },
  props: {
    color: {
      type: String,
      required: true
    },
    iconClass: {
      type: String,
      required: true
    },
    cardPanelText: {
      type: String,
      required: true
    },
    total: {
      type: Number,
      required: true
    },
    type: {
      type: String,
      default: ''
    },
    start: {
      type: Number,
      default: 0
    },
    duration: {
      type: Number,
      default: 3000
    },
    url: {
      type: String,
      default: ''
    },
    isChart: {
      type: Boolean,
      default: false
    },
    isDanger: {
      type: Boolean,
      default: false
    },
    labelText: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      isHover: false,
      styleBackground: {
        background: '#fff'
      },
      styleColor: {
        color: this.color
      }
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    },
    mouseenter() {
      this.styleBackground.background = this.color
      this.styleColor.color = '#fff'
    },
    mouseleave() {
      this.styleBackground.background = '#fff'
      this.styleColor.color = this.color
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.panel-group {
  margin-top: 18px;
  .card-panel-col{
    margin-bottom: 32px;
  }
  .card-panel {
    height: 108px;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 48px;
    }
    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 15px;
      margin-left: 0;
      .card-url:hover {
        color: #409EFF;
        text-decoration:underline;

      }
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.4);
        font-size: 16px;
        .card-panel-text-label{
          font-size: 10px;
          background-color: #C03639;
          color:#fff;
          display: inline-block;
          vertical-align:middle;
          line-height: 14px;
          margin: 0px -5px 4px 5px;
          text-align: center;
          width: 20px;
        }
        .label-danger{
          background-color: #C03639;
        }
        .label-normal{
          background-color: #409EFF;
        }
      }
      .card-panel-num {
        font-size: 20px;
        margin-top: 10px;
        display: block;
        text-align: center;
      }
      .card-panel-chart{
        margin: 5px auto;
        .card-panel-chart-icon{
          float: right;
          cursor: pointer;
          font-size: 14px;
          color:#409EFF
        }
      }
    }
  }
}
</style>
